package com.itheima.chapter11.tcp.demo;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class client {
    public static void main(String[] args) throws IOException {
        //创建socket对象，指定IP端口
        Socket socket =new Socket("127.0.0.1",8899);
        //获取传输数据的流对象
        InputStream is = socket.getInputStream();
        OutputStream os = socket.getOutputStream();
        //传输数据
        os.write("你好".getBytes());

        byte[] bys =new byte[1024];
        int len = is.read(bys);
        String msg = new String(bys, 0, len);
        System.out.println(msg);
        //关闭资源
        socket.close();

    }
}
